package com.woniuxy.queueProperties;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.woniuxy.utils.RabbitConnection;
import lombok.extern.log4j.Log4j2;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeoutException;

/**
 * @Author: linKe
 * @Date: 2022/1/10 15:49
 * @FileName: Producer
 * @version: 1.0
 * @Description: 设置队列属性
 */
@Log4j2
public class ProducerQueueProperties {

    public static void main(String[] args) throws IOException, TimeoutException, InterruptedException {
        Connection connection = RabbitConnection.getConnection();
        // 连接通道
        Channel channel = connection.createChannel();

        for (int i = 0; i < 100; i++) {
            /*
            (String exchange, String routingKey, boolean mandatory, BasicProperties props, byte[] body)
            发布消息。 如果资源驱动的警报 生效， Channel#basicPublish调用最终将被阻塞。
            参数：
                exchange 交换 - 将消息发布到的交换
                routingKey – 路由键
                mandatory 强制 - 如果要设置“强制”标志，则为 true    开启return的监听
                props - 消息的其他属性 - 路由标头等
                body 正文 - 消息正文
             */
            channel.basicPublish("exchangeQueueProperties", "test", true, null, ("邮箱服务..." + i).getBytes(StandardCharsets.UTF_8));
            /// channel.basicPublish("", "queueEmailWork", null, ("短信服务..."+i).getBytes(StandardCharsets.UTF_8));
            log.info("发送成功");
        }
        // 关闭资源
        //RabbitConnection.close(connection,channel);
    }
}
